	
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet" href="css/admin_add.css" />
<div class="body_top">
	<div>
		<p>团队管理</p>
		<div>
			<p>TEAM MANAGEMENT</p>
			<p class="last_p">ENTERPRENEURSHIP NETWORK TO CREATE INFINITE
				POSSIBILITY</p>
		</div>
	</div>
</div>
<div id="teac_all">
<form action="admin/addteam" method="post">
	<div class="add_teacbox clearfix" >
		<div>
			<p><b>团队名称</b><input type="text" name="te_name"><span></span></p>
			<p><b>用户名</b><input type="text" name="te_lonname"><span></span></p>
			<p><b>登录密码</b><input type="password" name="te_passw"><span></span></p>
			<p><b>确认密码</b><input type="password" name="te_passw"><span></span></p>
		</div>
		<div>
			<input type="submit" value="添加">
			<input id="cancel_teac" type="reset" value="取消" > 			
		</div>
	</div>
</form>
<div class="fenlei">
    <ul>
		<li>有无导师：</li>
		<li class="leixing" title="1">有</li>
		<li class="leixing" title="0">无</li>
	</ul>
</div>
<div class="ds clearfix yjds">
	<div class="tjds">
		<img src="img/tjds.png"><span>添加团队</span>
	</div>
	<div id="each_teac">
		<c:forEach items="${requestScope.teams }" var="team">
		<div>
			<div class="ds_left">
				<img src="${team.te_logo != null ? team.te_logo : 'img/project1.jpg'}">
			</div>
			<div class="ds_right">
			<span class="remove">一</span>
				<p>
					<b>ID:</b><span>${team.te_id }</span>
				</p>
				<p>
					<b>名字：</b><span>${team.te_name }</span>
				</p>
				<!-- <p>
					<span></span>${team.te_logo }
				</p> -->
				<p>
					<b>时间：</b>${team.te_ctime }
				</p>
				<p>
					<b>简介：</b>${team.te_explain }
				</p>
			</div>
			<div class="ds_bottom">
				<button>查看更多</button>
			</div>
		</div>
		</c:forEach>
		</div>
	</div>
	</div>
	<div class="fy" title="${sum != null?sum:1 }">
			<span id="pre_page">上一页</span>
			<ul>
			</ul>
			<span id="next_page">下一页</span>
		</div>


<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	//类型选择
	var kind="team";
	var type="";
	/*  var sum =$("div.fy").attr("title"); */
	var sum = 20;
	var connect_page=0;
	printList(1);
	$("li.leixing").click(function(){
		$(this).attr("id","bg_black");
		$(this).siblings().attr("id","");
		connect_data(kind,1,$(this).attr("title"));
	})
	//添加团队信息的弹出框
	$(".tjds").click(function(){
			$("div.add_teacbox").slideToggle();
		});
	$("#cancel_teac").click(function(){
		$("div.add_teacbox").slideUp();
	})

	
	//删除数据导师
	
		$("#each_teac").delegate('.remove','click',function(){
			if(confirm("确定删除?")){
				//取得被删导师的id值
				var tea_id = $(this).next().children('span').text();
				var that= $(this);
				//返回数据
				var obj_id={
                    type:"team",
					id:tea_id	
				};
				getData("admin/del",delete_teac,obj_id,that);
				
			}
		})
		
		//删除导师页面响应
		function delete_teac(data,that){
		if(data){
			that.parent().parent().css("display","none");
		}else{
			alert("删除失败，请重试！");
		}
	}
		//查看导师详细信息
		$("#each_teac").delegate('button','click',function(){
			var teac_id =$(this).parent().prev().children().eq(1).children().text();
			var that =$(this);
			var obj_id={
					id:teac_id
			}
			/* getData(address,see_teac,obj_id,that); */
			$("div.add_teacbox").slideDown();
		})
		
		function see_teac(data){
			console.log(data);
		}

// 分页及动态写数据	  admin/fenye?html=teac&&type=?&&page=?

	 
   function printList(index){
     var fy_html="";
     var show = sum-index>7?8:sum-index+1;
     if(index<=connect_page){
         for(var i=8;i>0;i--){
             fy_html+="<li>"+(index-i+1)+"</li>";
         }
         $(".fy>ul").html(fy_html);
         $(".fy>ul>li").eq(7).addClass('fy_on');
     }else{
         for(var i=0;i<show;i++){
             fy_html+="<li>"+(index+i)+"</li>";
         }
         $(".fy>ul").html(fy_html);
         $(".fy>ul>li").eq(0).addClass('fy_on');
     }
     connect_page=index;
 }
	    //点击分页  分别触发ajax事件以及分页列表事件
	    $(".fy>ul").delegate('li','click',function(){
	        type=$("#bg_black").attr("title");
	        $(this).addClass('fy_on');
	        $(this).siblings("li").attr("class","");
	        var page = $(this).html();
	        if(sum>8&&(page%7==1)&&page>7){
	            printList(Number(page));
	            }else{
	                connect_page=page;
	            }
	            connect_data(kind,page,type);
	            
	        })
	        
	        // 上一页  and 下一页
	$("#pre_page").click(function(){
     var pre_page=(connect_page-1)%7;
     pre_page= pre_page==0?7:pre_page;
     $("div.fy>ul>li").eq(pre_page-1).trigger("click");
 });
 
  $("#next_page").click(function(){
     var next_page=(Number(connect_page)+1)%7;
      next_page= next_page==0?7:next_page ;
      next_page= next_page==1?8:next_page ;
     $("div.fy>ul>li").eq(next_page-1).trigger("click");
 }) 
 
	//整合ajax地址
 function connect_data(kind,page,type){
     type= (type == undefined?"":"&&type="+type);
     var address ="admin/fenye?html="+kind+type+"&&page="+page;
     getData(address,printNews);
     console.log(address);
 }
 // ajax传值取相应数据
 function getData(address,callback,Data,that){
     $.ajax({
         type:"post",
         url:address,
         data:Data,
         dataType:"json",
         success:function(data){
             callback(data,that);
         },
         error:function(e){
             alert(e.message);
         }
     });
 }
	        
	//回调函数渲染页面
	function printNews(data){
		var teac_html="";
		$.each(data.paging,function(){
			teac_html+= "<div class='ds'><div class='ds_left'><img src='img/project1.jpg'/></div><div class='ds_right'><span class='remove'>一</span><p>ID:"+this.te_id+"</p><p>名称:"+this.te_name+"</p><p>帐号:"+this.te_loname+"</p><p>电话:"+this.te_tel+"</p></div><div class='ds_bottom'><button>查看更多</button></div></div>";
		});
		$("#each_teac").html(teac_html);
	}
	//添加团队信息
	function printTeam(){
		$.ajax({
			url : "",
			data:{} ,
			datatype : "json",
			type : "post",
			success : function(data){
				
			},
			error : function(){
				alert(error);
			}
		})
	}
	
})
</script>